-
Couldn't load subscription status.
- Fork 270
Fix YamlConverter adding extra quotes to string values when converting from JSON to YAML #2562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
|
@copilot also add a unit test to validate the conversion respects line breaks in string values |
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Added unit test |
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
|



Problem
The
YamlConverter.ToYamlNode()method was adding extra quotes to string values when converting from JSON to YAML, causing incorrect output:Previous (Incorrect) Output:
Expected Output:
Root Cause
The
ToYamlScalarmethod was usingJsonValue.ToJsonString()to extract values. This method returns the JSON representation of a value, which includes quotes around strings. When these quoted strings were passed toYamlScalarNode, the YAML serializer treated the quotes as part of the actual string content and escaped them, resulting in double-quoted output.Solution
Modified
ToYamlScalarto:TryGetValue<string>()instead ofToJsonString()to get the underlying value without JSON formatting"fooStringValue") → output unquoted asfooStringValue"200","true","null") → output quoted as"200","true","null"to preserve type information during round-tripping200,trueThis ensures proper type preservation when converting between JSON and YAML while producing clean, readable YAML output.
Testing
Added 11 comprehensive unit tests covering:
All existing tests continue to pass with no regressions.
Fixes #1951
Original prompt
Fixes #2561
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.